package com.yuexun.beilunpatient.ui.satisfaction.presenter.impl;

import com.yuexun.beilunpatient.base.BaseEntity;
import com.yuexun.beilunpatient.ui.satisfaction.bean.SatisfactionAnswerDtlBean;
import com.yuexun.beilunpatient.ui.satisfaction.bean.SatisfactionDtlBean;
import com.yuexun.beilunpatient.ui.satisfaction.model.ISatisfactionModel;
import com.yuexun.beilunpatient.ui.satisfaction.presenter.ISatisfactionDtlPresenter;
import com.yuexun.beilunpatient.ui.satisfaction.ui.view.ISatisfactionDtlView;

import org.kymjs.kjframe.ui.ViewInject;

import java.util.Map;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by chenss on 2018/8/29.
 */
public class SatisfactionDtlPresenter implements ISatisfactionDtlPresenter {

    private ISatisfactionDtlView view;
    private ISatisfactionModel model;

    //记录Log
//    private final Logger log = ProUtil.getLogger(LoginPresneter.class);

    public SatisfactionDtlPresenter(ISatisfactionModel model, ISatisfactionDtlView view) {
        this.model = model;
        this.view = view;
    }

    @Override
    public void getSatisfactionDtl(Map<String, String> praise) {
        model.getSatisfactionDtl(praise)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<BaseEntity<SatisfactionDtlBean>>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        ViewInject.toast("获取题库详情失败");
                    }

                    @Override
                    public void onNext(BaseEntity<SatisfactionDtlBean> entity) {
                        view.getSatisfactionDtl(entity);
                    }
                });
    }

    @Override
    public void getSatisfactionAnswerDtl(Map<String, String> praise) {
        model.getSatisfactionAnswerDtl(praise)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<BaseEntity<SatisfactionAnswerDtlBean>>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        ViewInject.toast("请检查网络状态");
                    }

                    @Override
                    public void onNext(BaseEntity<SatisfactionAnswerDtlBean> entity) {
                        view.getSatisfactionAnswerDtl(entity);
                    }
                });
    }
}
